package com.ajr.core.visma;

public class ExportResult {
	int status = 0;
	String message = "";
	String customerNumber = "";
	String orderNumber = "";
	String exportStatus = "Success";
	String messageCode = "";
	
	public String getMessageCode() {
		return messageCode;
	}
	public void setMessageCode(String messageCode) {
		this.messageCode = messageCode;
	}

	public static String OSC_CUSTOMER_UPDATE_SUCCESS_CODE = "3";
	public static String OSC_CUSTOMER_EXPORT_SUCCESS_CODE = "2";
	public static String OSC_CUSTOMER_INVALID_CODE = "23";
	public static String OSC_CUSTOMER_EXISTS_CODE = "24";
	public static String OSC_CUSTOMER_EXPORT_FAILURE_CODE = "25";

	public static String OSC_ORDER_EXPORT_SUCCESS_CODE = "1";
	public static String OSC_ORDER_INVALID_CODE = "21";
	public static String OSC_ORDER_EXPORT_FAILURE_CODE = "22";
	public static String OSC_ORDER_EXPORT_NOTHING_CODE = "26";
	
	public boolean isStatus() {
		return (status == 1);
	}
	public void setStatus(boolean status) {
		if(status) {
			this.status = 1;
		}else {
			this.status = 0;
		}
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String messageCode,String message) {
		this.messageCode = messageCode;
		this.message = message;
	}
	public void setOrderNumber(String number) {
		this.orderNumber = number;
	}
	public void setCustomerNumber(String number) {
		this.customerNumber = number;
	}
	public String getResultMessage() {
		if(status == 1) {
			return getMessage() + ":"+ orderNumber + ":"+customerNumber;
		}
		return message;
	}

	public String getXMLResponse() {
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("<?xml version='1.0' encoding='ISO-8859-1'?>");
		//stringBuilder.append("<?xml-stylesheet type=\"text/xsl\" href=\"result.xslt\"?>");
		  stringBuilder.append("<result>");
		  stringBuilder.append("<status>" +status+ "</status>");
		  stringBuilder.append("<orderNumber>"+orderNumber+  "</orderNumber>");
		  stringBuilder.append("<customerNumber>"+customerNumber+  "</customerNumber>");
		  stringBuilder.append("<message>"+message+  "</message>");
		  stringBuilder.append("<statusFlag>"+exportStatus+  "</statusFlag>");
		  stringBuilder.append("</result>");
		return stringBuilder.toString();
	}
	
	public String getResponseText() {
		StringBuilder stringBuilder = new StringBuilder();
		//stringBuilder.append("<?xml-stylesheet type=\"text/xsl\" href=\"result.xslt\"?>");
		  stringBuilder.append("status:" +status+";");
		  stringBuilder.append("orderNumber:"+orderNumber+  ";");
		  stringBuilder.append("customerNumber:"+customerNumber+  ";");
		  stringBuilder.append("message:"+message+  ";");
		  stringBuilder.append("statusFlag:"+exportStatus+  ";");
		return stringBuilder.toString();
	}

	
	public String getHtmlResponse(String page,String orderId,String customerId) {
		StringBuilder stringBuilder = new StringBuilder();
		String urlParams = "page="+page+"&oID="+orderId+"&exportStatus="+exportStatus
			+"&action=edit&exportSPCS="+((status==1)?"success":"failure")
			+"&order==" +((orderNumber.length()>0)?"true":"false")+
			"&customer=" +((customerNumber.length()>0)?"true":"false")+
			"&customerID="+customerId;
		stringBuilder.append("<html><head>");
		stringBuilder.append("<script src=\"http://localhost:8080/JInterWeb/scripts/refresh.js\" language=\"javascript\"></script>");
		  stringBuilder.append("</head><body>");
		  stringBuilder.append("<br/>");
		  stringBuilder.append("<input type=hidden value=\""+orderNumber+  "\">");
		  stringBuilder.append("<input type=hidden value=\""+customerNumber+  "\">");
		  stringBuilder.append("<span>"+message+  "</span>");
		  stringBuilder.append("<br/>");
		  stringBuilder.append("<br/><center><input type=button value=OK onClick=\"closeWindowFunction('"+urlParams+"');\"/></center>");
		  stringBuilder.append("</body></html><script>closeWindowFunction('"+urlParams+"');</script>");
		return stringBuilder.toString();
		
	}
	public String getCustomerNumber() {
		return customerNumber;
	}
	public String getOrderNumber() {
		return orderNumber;
	}
	
	int customerGroupShowTaxId = 0;
	public void setCustomerGroupShowTaxId(int customerGroupShowTaxId) {
		this.customerGroupShowTaxId = customerGroupShowTaxId;
		
	}
	public int getCustomerGroupShowTaxId() {
		return customerGroupShowTaxId;
		
	}
	
	boolean customerExists = true;
	public boolean isCustomerExists() {
		return customerExists;
	}
	
	public void setCustomerExists(boolean customerExists) {
		this.customerExists = customerExists;
	}
	int customerGroupId = 0;
	public void setCustomerGroupId(int customerGroupId) {
		this.customerGroupId = customerGroupId;
	}
	public int getCustomerGroupId() {
		// TODO Auto-generated method stub
		return customerGroupId;
	}
	public String getStatusCode() {
		if(status == 1) {
			return "success";
		} else if(status == 0) {
			return "warning";
		}
		return "error";
	}
	
	public void setError() {
		this.status = 1;
	}
	
}
